<?php
defined('DCS_ROOT') or exit(header("HTTP/1.1 430 Not Forbidden"));

class main {	
	function __construct() {		
		$this->defaultAction();
		exit();
	}
	function defaultAction(){		
		$tpl = new Template("movie/search.htm" );
		$db  = getDB();
		$keyword = addslashes(trim($_GET['keywords']));

		if(!empty($keyword)){
			$keyword = htmlClear($keyword);

			if (strlen($keyword) < 2) {
				message('关键字不能少于2个字符');
			}

			$is_key = strstr($keyword,'%');
			if(!empty($is_key)){
				message('关键字不能为空');
			}

			$url = getUrl();
			if($url['params']['1'] == 'page'){
				$pagetemp = $url['params']['2'];		
			}

			$param['table'] = 'movie ';
			$param['field'] = ' id,title,descs,thumb,ratings,comments,review ';
			$param['where'] = " title LIKE '%$keyword%' OR descs LIKE '%$keyword%' ";
			$param['order'] = 'review DESC';
			$param['page']= is_numeric($pagetemp) ? $pagetemp :'1';		
			$param['rows'] = '30';
			$param['pageUrl'] = '/search/page/';
			$param['pageTotal']	= $db->getTotal($param);		
			$movies = $db->getList($param);
	

			if(!empty($movies)){
				foreach($movies as $k=>$v){
					$movies[$k]['k'] = $k + 1;
					$movies[$k]['descs'] = highlightWords(html2Txt($v['descs']),$keyword);
					$movies[$k]['titles'] = highlightWords($v['title'],$keyword);
				}
			}
			//de($play_movie);
			$tpl->assign("movie_search", $movies);
			$pages =  makePage($param);
			$tpl->assign("pages",$pages);
			$tpl->assign(assignUser());
			$tpl->assign("debuginfo",debuginfo().$db->getQueryTimes().' 次查询');
			$tpl->output();

		}

	}


}

?>
